extends Node2D

var hp=10 setget set_hp
var hp_max=10 setget set_hp_max
onready var bar=$ColorRect/ColorRect/bar
#
func set_hp(value):
	hp=value
	$Label.text=str(hp)+"/"+str(hp_max)
func set_hp_max(value):
	hp_max=value
	$Label.text=str(hp)+"/"+str(hp_max)

var barRate=1 setget set_barRate#进度条比例
func set_barRate(value):
	barRate=value
	updateBar()

func _ready():
	# Called when the node is added to the scene for the first time.
	# Initialization here
	pass

func updateBar():
	bar.margin_right=barRate*117
	

func _process(delta):
	var rate=floor(hp)/hp_max
	if barRate!=rate:
		if abs(barRate-rate)<=0.5*delta:
			self.barRate=rate
		else:
			self.barRate+=-sign(barRate-rate)*0.5*delta

func onHpChange(h,hp_max_):
	self.hp_max=hp_max_
	self.hp=h
	


